package ui.handlers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import ui.ViewTransactionScreen;

public class ViewTransactionHandler implements ActionListener {

	private int transactionID;
	private ViewTransactionScreen viewTransactionScreen;
	
	private JFrame frame;
	
	public ViewTransactionHandler(int transactionID, ViewTransactionScreen screen)
	{ this.transactionID = transactionID; this.viewTransactionScreen = screen;}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		try {
			String text = "<HTML><PRE>"+ viewTransactionScreen.getStore().getTransactionReciept(transactionID) +"</PRE></HTML>";
			JPanel panel = new JPanel();
			panel.add(new JLabel(text));
			
			frame = new JFrame();
			frame.setTitle("Transaction: "+ viewTransactionScreen.getStore().getCustomerNameByTransaction(transactionID));
			frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			frame.setSize(650, 550);
			frame.add(panel);
			frame.setVisible(true);
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}